package com.example.activitysign.controller;

import com.example.activitysign.pages.AjaxResult;
import com.example.activitysign.pages.PageResult;
import com.example.activitysign.pages.PageValidate;
import com.example.activitysign.service.IActivityUserAwardService;
import com.example.activitysign.validate.ActivityUserAwardCreateValidate;
import com.example.activitysign.validate.ActivityUserAwardSearchValidate;
import com.example.activitysign.validate.ActivityUserAwardUpdateValidate;
import com.example.activitysign.vo.activity.ActivityUserAwardDetailVo;
import com.example.activitysign.vo.activity.ActivityUserAwardListedVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 用户奖品管理
 */
@Slf4j
@RestController
@RequestMapping("api/activityUserAward")
public class ActivityUserAwardController {

    @Resource
    private IActivityUserAwardService iActivityUserAwardService;

    @GetMapping("/list")
    public AjaxResult<PageResult<ActivityUserAwardListedVo>> list(@Validated PageValidate pageValidate,
                                                                  @Validated ActivityUserAwardSearchValidate searchValidate) {
        PageResult<ActivityUserAwardListedVo> list = iActivityUserAwardService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    public AjaxResult<ActivityUserAwardDetailVo> detail(@Validated @RequestParam("id") Long id) {
        ActivityUserAwardDetailVo detail = iActivityUserAwardService.detail(id);
        return AjaxResult.success(detail);
    }

    /**
     * 用户奖品新增
     *
     * @param createValidate
     * @return
     */
    @PostMapping("/add")
    public AjaxResult<Object> add(@Validated @RequestBody ActivityUserAwardCreateValidate createValidate) {
        iActivityUserAwardService.add(createValidate);
        return AjaxResult.success();
    }

    /**
     * 用户奖品编辑
     *
     * @param updateValidate
     * @return
     */
    @PostMapping("/edit")
    public AjaxResult<Object> edit(@Validated @RequestBody ActivityUserAwardUpdateValidate updateValidate) {
        iActivityUserAwardService.edit(updateValidate);
        return AjaxResult.success();
    }


}
